home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / senjyo.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  12KB  |  480 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10.  
  11. /* in machine/segacrpt.c */
  12. void suprloco_decode(void);
  13.  
  14.  
  15. extern unsigned char *spriteram;
  16. extern size_t spriteram_size;
  17.  
  18. unsigned char *senjyo_fgscroll;
  19. unsigned char *senjyo_bgstripes;
  20. unsigned char *senjyo_scrollx1,*senjyo_scrolly1;
  21. unsigned char *senjyo_scrollx2,*senjyo_scrolly2;
  22. unsigned char *senjyo_scrollx3,*senjyo_scrolly3;
  23. unsigned char *senjyo_fgvideoram,*senjyo_fgcolorram;
  24. unsigned char *senjyo_bg1videoram,*senjyo_bg2videoram,*senjyo_bg3videoram;
  25. unsigned char *senjyo_radarram;
  26.  
  27. static struct tilemap *fg_tilemap,*bg1_tilemap,*bg2_tilemap,*bg3_tilemap;
  28.  
  29. static int senjyo, scrollhack;
  30.  
  31. static struct osd_bitmap *bgbitmap;
  32. static int bgbitmap_dirty;
  33. static int flipscreen;
  34.  
  35.  
  36. void init_starforc(void)
  37. {
  38.     senjyo = 0;
  39.     scrollhack = 1;
  40. }
  41. void init_starfore(void)
  42. {
  43.     /* encrypted CPU */
  44.     suprloco_decode();
  45.  
  46.     senjyo = 0;
  47.     scrollhack = 0;
  48. }
  49. void init_senjyo(void)
  50. {
  51.     senjyo = 1;
  52.     scrollhack = 0;
  53. }
  54.  
  55.  
  56. /***************************************************************************
  57.  
  58.   Callbacks for the TileMap code
  59.  
  60. ***************************************************************************/
  61.  
  62. static void get_fg_tile_info(int tile_index)
  63. {
  64.     unsigned char attr = senjyo_fgcolorram[tile_index];
  65.     SET_TILE_INFO(0,senjyo_fgvideoram[tile_index] + ((attr & 0x10) << 4),attr & 0x07)
  66.     tile_info.flags = (attr & 0x80) ? TILE_FLIPY : 0;
  67.     if (senjyo && (tile_index & 0x1f) >= 32-8)
  68.         tile_info.flags |= TILE_IGNORE_TRANSPARENCY;
  69. }
  70.  
  71. static void senjyo_bg1_tile_info(int tile_index)
  72. {
  73.     unsigned char code = senjyo_bg1videoram[tile_index];
  74.     SET_TILE_INFO(1,code,(code & 0x70) >> 4)
  75. }
  76.  
  77. static void starforc_bg1_tile_info(int tile_index)
  78. {
  79.     /* Star Force has more tiles in bg1, so to get a uniform color code spread */
  80.     /* they wired bit 7 of the tile code in place of bit 4 to get the color code */
  81.     static int colormap[8] = { 0,2,4,6,1,3,5,7 };
  82.     unsigned char code = senjyo_bg1videoram[tile_index];
  83.     SET_TILE_INFO(1,code,colormap[(code & 0xe0) >> 5])
  84. }
  85.  
  86. static void get_bg2_tile_info(int tile_index)
  87. {
  88.     unsigned char code = senjyo_bg2videoram[tile_index];
  89.     SET_TILE_INFO(2,code,(code & 0xe0) >> 5)
  90. }
  91.  
  92. static void get_bg3_tile_info(int tile_index)
  93. {
  94.     unsigned char code = senjyo_bg3videoram[tile_index];
  95.     SET_TILE_INFO(3,code,(code & 0xe0) >> 5)
  96. }
  97.  
  98.  
  99.  
  100. /***************************************************************************
  101.  
  102.   Start the video hardware emulation.
  103.  
  104. ***************************************************************************/
  105.  
  106. void senjyo_vh_stop(void)
  107. {
  108.     osd_free_bitmap(bgbitmap);
  109.     bgbitmap = 0;
  110. }
  111.  
  112. int senjyo_vh_start(void)
  113. {
  114.     bgbitmap = osd_create_bitmap(256,256);
  115.     if (!bgbitmap)
  116.         return 1;
  117.  
  118.     fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
  119.     if (senjyo)
  120.     {
  121.         bg1_tilemap = tilemap_create(senjyo_bg1_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,16,32);
  122.         bg2_tilemap = tilemap_create(get_bg2_tile_info,   tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,16,48);    /* only 16x32 used by Star Force */
  123.         bg3_tilemap = tilemap_create(get_bg3_tile_info,   tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,16,56);    /* only 16x32 used by Star Force */
  124.     }
  125.     else
  126.     {
  127.         bg1_tilemap = tilemap_create(starforc_bg1_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,16,32);
  128.         bg2_tilemap = tilemap_create(get_bg2_tile_info,     tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,16,32);    /* only 16x32 used by Star Force */
  129.         bg3_tilemap = tilemap_create(get_bg3_tile_info,     tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,16,32);    /* only 16x32 used by Star Force */
  130.     }
  131.  
  132.  
  133.     if (!fg_tilemap || !bg1_tilemap || !bg2_tilemap || !bg3_tilemap)
  134.     {
  135.         senjyo_vh_stop();
  136.  
  137.         return 1;
  138.     }
  139.  
  140.     fg_tilemap->transparent_pen = 0;
  141.     bg1_tilemap->transparent_pen = 0;
  142.     bg2_tilemap->transparent_pen = 0;
  143.     bg3_tilemap->transparent_pen = 0;
  144.     tilemap_set_scroll_cols(fg_tilemap,32);
  145.  
  146.     bgbitmap_dirty = 1;
  147.  
  148.     return 0;
  149. }
  150.  
  151.  
  152.  
  153. /***************************************************************************
  154.  
  155.   Memory handlers
  156.  
  157. ***************************************************************************/
  158.  
  159. WRITE_HANDLER( senjyo_fgvideoram_w )
  160. {
  161.     if (senjyo_fgvideoram[offset] != data)
  162.     {
  163.         senjyo_fgvideoram[offset] = data;
  164.         tilemap_mark_tile_dirty(fg_tilemap,offset);
  165.     }
  166. }
  167. WRITE_HANDLER( senjyo_fgcolorram_w )
  168. {
  169.     if (senjyo_fgcolorram[offset] != data)
  170.     {
  171.         senjyo_fgcolorram[offset] = data;
  172.         tilemap_mark_tile_dirty(fg_tilemap,offset);
  173.     }
  174. }
  175. WRITE_HANDLER( senjyo_bg1videoram_w )
  176. {
  177.     if (senjyo_bg1videoram[offset] != data)
  178.     {
  179.         senjyo_bg1videoram[offset] = data;
  180.         tilemap_mark_tile_dirty(bg1_tilemap,offset);
  181.     }
  182. }
  183. WRITE_HANDLER( senjyo_bg2videoram_w )
  184. {
  185.     if (senjyo_bg2videoram[offset] != data)
  186.     {
  187.         senjyo_bg2videoram[offset] = data;
  188.         tilemap_mark_tile_dirty(bg2_tilemap,offset);
  189.     }
  190. }
  191. WRITE_HANDLER( senjyo_bg3videoram_w )
  192. {
  193.     if (senjyo_bg3videoram[offset] != data)
  194.     {
  195.         senjyo_bg3videoram[offset] = data;
  196.         tilemap_mark_tile_dirty(bg3_tilemap,offset);
  197.     }
  198. }
  199.  
  200. WRITE_HANDLER( senjyo_bgstripes_w )
  201. {
  202.     if (*senjyo_bgstripes != data)
  203.     {
  204.         *senjyo_bgstripes = data;
  205.         bgbitmap_dirty = 1;
  206.     }
  207. }
  208.  
  209. WRITE_HANDLER( senjyo_flipscreen_w )
  210. {
  211.     flipscreen = data & 0x01;
  212.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPX | TILEMAP_FLIPY) : 0);
  213. }
  214.  
  215.  
  216. /***************************************************************************
  217.  
  218.   Display refresh
  219.  
  220. ***************************************************************************/
  221.  
  222. static void draw_bgbitmap(struct osd_bitmap *bitmap)
  223. {
  224.     int x,y,pen,strwid,count;
  225.  
  226.  
  227.     if (*senjyo_bgstripes == 0xff)    /* off */
  228.     {
  229.         fillbitmap(bitmap,Machine->pens[0],0);
  230.         return;
  231.     }
  232.  
  233.     if (bgbitmap_dirty)
  234.     {
  235.         bgbitmap_dirty = 0;
  236.  
  237.         pen = 0;
  238.         count = 0;
  239.         strwid = *senjyo_bgstripes;
  240.         if (strwid == 0) strwid = 0x100;
  241.         if (flipscreen) strwid ^= 0xff;
  242.  
  243.         for (x = 0;x < 256;x++)
  244.         {
  245.             if (flipscreen)
  246.             {
  247.                 for (y = 0;y < 256;y++)
  248.                 {
  249.                     plot_pixel(bgbitmap, 255 - x, y, Machine->pens[384 + pen]);
  250.                 }
  251.             }
  252.             else
  253.             {
  254.                 for (y = 0;y < 256;y++)
  255.                 {
  256.                     plot_pixel(bgbitmap, x, y, Machine->pens[384 + pen]);
  257.                 }
  258.             }
  259.  
  260.             count += 0x10;
  261.             if (count >= strwid)
  262.             {
  263.                 pen = (pen + 1) & 0x0f;
  264.                 count -= strwid;
  265.             }
  266.         }
  267.     }
  268.  
  269.     copybitmap(bitmap,bgbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  270. }
  271.  
  272. static void draw_radar(struct osd_bitmap *bitmap)
  273. {
  274.     int offs,x;
  275.  
  276.     for (offs = 0;offs < 0x400;offs++)
  277.     {
  278.         if (senjyo_radarram[offs])
  279.         {
  280.             for (x = 0;x < 8;x++)
  281.             {
  282.                 if (senjyo_radarram[offs] & (1 << x))
  283.                 {
  284.                     int sx, sy;
  285.  
  286.                     sx = (8 * (offs % 8) + x) + 256-64;
  287.                     sy = ((offs & 0x1ff) / 8) + 96;
  288.  
  289.                     if (flipscreen)
  290.                     {
  291.                         sx = 255 - sx;
  292.                         sy = 255 - sy;
  293.                     }
  294.  
  295.                     plot_pixel(bitmap,
  296.                                sx, sy,
  297.                                Machine->pens[offs < 0x200 ? 400 : 401]);
  298.                 }
  299.             }
  300.         }
  301.     }
  302. }
  303.  
  304. static void draw_sprites(struct osd_bitmap *bitmap,int priority)
  305. {
  306.     const struct rectangle *clip = &Machine->drv->visible_area;
  307.     int offs;
  308.  
  309.  
  310.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  311.     {
  312.         int big,sx,sy,flipx,flipy;
  313.  
  314.         if (((spriteram[offs+1] & 0x30) >> 4) == priority)
  315.         {
  316.             if (senjyo)    /* Senjyo */
  317.                 big = (spriteram[offs] & 0x80);
  318.             else    /* Star Force */
  319.                 big = ((spriteram[offs] & 0xc0) == 0xc0);
  320.             sx = spriteram[offs+3];
  321.             if (big)
  322.                 sy = 224-spriteram[offs+2];
  323.             else
  324.                 sy = 240-spriteram[offs+2];
  325.             flipx = spriteram[offs+1] & 0x40;
  326.             flipy = spriteram[offs+1] & 0x80;
  327.  
  328.             if (flipscreen)
  329.             {
  330.                 flipx = !flipx;
  331.                 flipy = !flipy;
  332.  
  333.                 if (big)
  334.                 {
  335.                     sx = 224 - sx;
  336.                     sy = 226 - sy;
  337.                 }
  338.                 else
  339.                 {
  340.                     sx = 240 - sx;
  341.                     sy = 242 - sy;
  342.                 }
  343.             }
  344.  
  345.  
  346.             drawgfx(bitmap,Machine->gfx[big ? 5 : 4],
  347.                     spriteram[offs],
  348.                     spriteram[offs + 1] & 0x07,
  349.                     flipx,flipy,
  350.                     sx,sy,
  351.                     clip,TRANSPARENCY_PEN,0);
  352.         }
  353.     }
  354. }
  355.  
  356. void senjyo_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  357. {
  358.     int i;
  359.  
  360.  
  361.     /* two colors for the radar dots (verified on the real board) */
  362.     palette_change_color(400,0xff,0x00,0x00);    /* red for enemies */
  363.     palette_change_color(401,0xff,0xff,0x00);    /* yellow for player */
  364.  
  365.     {
  366.         int scrollx,scrolly;
  367.  
  368.         for (i = 0;i < 32;i++)
  369.             tilemap_set_scrolly(fg_tilemap,i,senjyo_fgscroll[i]);
  370.  
  371.         scrollx = senjyo_scrollx1[0];
  372.         scrolly = senjyo_scrolly1[0] + 256 * senjyo_scrolly1[1];
  373.         if (flipscreen)
  374.             scrollx = -scrollx;
  375.         tilemap_set_scrollx(bg1_tilemap,0,scrollx);
  376.         tilemap_set_scrolly(bg1_tilemap,0,scrolly);
  377.  
  378.         scrollx = senjyo_scrollx2[0];
  379.         scrolly = senjyo_scrolly2[0] + 256 * senjyo_scrolly2[1];
  380.         if (scrollhack)    /* Star Force, but NOT the encrypted version */
  381.         {
  382.             scrollx = senjyo_scrollx1[0];
  383.             scrolly = senjyo_scrolly1[0] + 256 * senjyo_scrolly1[1];
  384.         }
  385.         if (flipscreen)
  386.             scrollx = -scrollx;
  387.         tilemap_set_scrollx(bg2_tilemap,0,scrollx);
  388.         tilemap_set_scrolly(bg2_tilemap,0,scrolly);
  389.  
  390.         scrollx = senjyo_scrollx3[0];
  391.         scrolly = senjyo_scrolly3[0] + 256 * senjyo_scrolly3[1];
  392.         if (flipscreen)
  393.             scrollx = -scrollx;
  394.         tilemap_set_scrollx(bg3_tilemap,0,scrollx);
  395.         tilemap_set_scrolly(bg3_tilemap,0,scrolly);
  396.     }
  397.  
  398.     tilemap_update(ALL_TILEMAPS);
  399.  
  400.     palette_init_used_colors();
  401. //    mark_sprite_colors();
  402.     for (i = 320; i < 384; i++)
  403.     {
  404.         if (i % 8 != 0)
  405.             palette_used_colors[i] = PALETTE_COLOR_USED;
  406.     }
  407.     for (i = 384; i < 400; i++)
  408.     {
  409.         palette_used_colors[i] = PALETTE_COLOR_USED;
  410.     }
  411.     palette_used_colors[400] = PALETTE_COLOR_USED;
  412.     palette_used_colors[401] = PALETTE_COLOR_USED;
  413.  
  414.     if (palette_recalc())
  415.     {
  416.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  417.         bgbitmap_dirty = 1;
  418.     }
  419.  
  420.     tilemap_render(ALL_TILEMAPS);
  421.  
  422.     draw_bgbitmap(bitmap);
  423.     draw_sprites(bitmap,0);
  424.     tilemap_draw(bitmap,bg3_tilemap,0);
  425.     draw_sprites(bitmap,1);
  426.     tilemap_draw(bitmap,bg2_tilemap,0);
  427.     draw_sprites(bitmap,2);
  428.     tilemap_draw(bitmap,bg1_tilemap,0);
  429.     draw_sprites(bitmap,3);
  430.     tilemap_draw(bitmap,fg_tilemap,0);
  431.     draw_radar(bitmap);
  432.  
  433. #if 0
  434. {
  435.     char baf[80];
  436.  
  437.     sprintf(baf,"%02x %02x %02x %02x %02x %02x %02x %02x",
  438.         senjyo_scrolly3[0x00],
  439.         senjyo_scrolly3[0x01],
  440.         senjyo_scrolly3[0x02],
  441.         senjyo_scrolly3[0x03],
  442.         senjyo_scrolly3[0x04],
  443.         senjyo_scrolly3[0x05],
  444.         senjyo_scrolly3[0x06],
  445.         senjyo_scrolly3[0x07]);
  446.     ui_text(baf,0,0);
  447.     sprintf(baf,"%02x %02x %02x %02x %02x %02x %02x %02x",
  448.         senjyo_scrolly3[0x08],
  449.         senjyo_scrolly3[0x09],
  450.         senjyo_scrolly3[0x0a],
  451.         senjyo_scrolly3[0x0b],
  452.         senjyo_scrolly3[0x0c],
  453.         senjyo_scrolly3[0x0d],
  454.         senjyo_scrolly3[0x0e],
  455.         senjyo_scrolly3[0x0f]);
  456.     ui_text(baf,0,10);
  457.     sprintf(baf,"%02x %02x %02x %02x %02x %02x %02x %02x",
  458.         senjyo_scrolly3[0x10],
  459.         senjyo_scrolly3[0x11],
  460.         senjyo_scrolly3[0x12],
  461.         senjyo_scrolly3[0x13],
  462.         senjyo_scrolly3[0x14],
  463.         senjyo_scrolly3[0x15],
  464.         senjyo_scrolly3[0x16],
  465.         senjyo_scrolly3[0x17]);
  466.     ui_text(baf,0,20);
  467.     sprintf(baf,"%02x %02x %02x %02x %02x %02x %02x %02x",
  468.         senjyo_scrolly3[0x18],
  469.         senjyo_scrolly3[0x19],
  470.         senjyo_scrolly3[0x1a],
  471.         senjyo_scrolly3[0x1b],
  472.         senjyo_scrolly3[0x1c],
  473.         senjyo_scrolly3[0x1d],
  474.         senjyo_scrolly3[0x1e],
  475.         senjyo_scrolly3[0x1f]);
  476.     ui_text(baf,0,30);
  477. }
  478. #endif
  479. }
  480.